package com.jtlrm.ckd.mvp.view.adapter;

import android.support.annotation.NonNull;
import android.view.View;

import com.base.sdk.util.DateFormatUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jtlrm.ckd.R;
import com.jtlrm.ckd.entity.LiangBiaoEntity;

import java.text.ParseException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class LiangBiaoAdapter extends BaseQuickAdapter<LiangBiaoEntity, BaseViewHolder> {

    Set<String> hasMonth = new HashSet<>(); // 已存在的月份
    DateFormatUtil dateFormatUtil = new DateFormatUtil();

    public LiangBiaoAdapter() {
        super(R.layout.liangbiao_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, LiangBiaoEntity item) {
        try {
            helper.setText(R.id.content, item.getCreateTime().substring(0, item.getCreateTime().indexOf(" ")));
            String month = dateFormatUtil.getMonth(item.getCreateTime());
            if (hasMonth.contains(month)) {
                helper.getView(R.id.date).setVisibility(View.GONE);
            } else {
                hasMonth.add(month);
                helper.getView(R.id.date).setVisibility(View.VISIBLE);
                helper.setText(R.id.date, month + "月");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void replaceData(@NonNull Collection<? extends LiangBiaoEntity> data) {
        hasMonth.clear();
        super.replaceData(data);
    }
}
